<%--
    Document   : profil
    Created on : 16 avr. 2011, 14:58:41
    Author     : Jeremy Romano
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="../include/header.jsp" %>

<div id="main">
    <div id="container">
        <div id="content">
            <div id="post-898" class="hentry p1 post publish author-admin category-blogs category-companies tag-blue tag-brown comments-open pings-closed y2009 m08 d16 h13 slug-envira-media">
                <div id="resultPartage" class="entry-content">
                    <ul class="meta">
                        <c:if test="${!empty requestScope['utilisateurs']}">
                            <c:forEach var="utilisateur" items="${requestScope['utilisateurs']}">
                                <li id="${utilisateur.id}">
                                    ${utilisateur.login}<a onclick="supprime(${utilisateur.id},${requestScope['id']})" class="alignright" href="#">Supprimer</a>
                                </li>
                            </c:forEach>
                        </c:if>
                    </ul>
                </div>

            </div><!-- .post -->
            <div  style="float:left;  margin-left: -935px">
                <h2>${requestScope['nomAlbum']}</h2>
                <form id="partageForm">
                    Recherche par login :  <input name="login" id="login" type="text" class="required" size="25" />
                    <input type="button" onclick="lookupAjax()" value="Ajouter" />
                    <input type="hidden" value="${requestScope['id']}" id="idAlbum" name="idAlbum"/>
                </form>
                <script type="text/javascript">

                    function supprime(idUtilisateur, idAlbum)
                    {
                        $.getJSON('./AlbumServlet', {action:"deletePartage", idUtilisateur:idUtilisateur, idAlbum:idAlbum}, function(data){
                                if (data.ret) {
                                    // On ajoute le nouvel élément
                                    $("li#" + data.id).remove();
                                }
                                else {
                                    //$('#contenu').after('<span class="erreur">Erreur lors de l\'ajout du commentaire</span>');
                                    //$('.ok').hide().fadeIn('slow');
                                }
                            });
                    }

                    function findValue(li) {
                        if( li == null ) return alert("Login inexistant !");

                        // if coming from an AJAX call, let's use the CityId as the value
                        if( !!li.extra ) var sValue = li.extra[0];

                        // otherwise, let's just display the value in the text box
                        else {
                            var sValue = li.selectValue;
                            var idAlbum = $('#idAlbum').val();

                            $("#login").val("");

                            $.getJSON('./AlbumServlet', {action:"addPartage", login:sValue, idAlbum:idAlbum}, function(data){
                                if (data.ret) {
                                    // On ajoute le nouvel élément
                                    var str = "<li id=\""
                                        + data.id
                                        + "\">"
                                        + data.login
                                        + "<a onclick=\"supprime("
                                        + data.id
                                        + ","
                                        + data.idAlbum
                                        + ")\" class=\"alignright\" href=\"#\">Supprimer</a>"
                                        + "</li>";
                                    $('#resultPartage ul').append(str);
                                }
                                else {
                                    //$('#contenu').after('<span class="erreur">Erreur lors de l\'ajout du commentaire</span>');
                                    //$('.ok').hide().fadeIn('slow');
                                }
                            });
                        }
                    }

                    function selectItem(li) {
                        findValue(li);
                    }

                    function formatItem(row) {
                        return row[0];
                    }

                    function lookupAjax(){
                        var oSuggest = $("#login")[0].autocompleter;
                        oSuggest.findValue();
                        return false;
                    }

                    function lookupLocal(){
                        var oSuggest = $("#login")[0].autocompleter;

                        oSuggest.findValue();

                        return false;
                    }


                    $("#login").autocomplete(
                    "LoginServlet?action=allLogins&",
                    {
                        delay:10,
                        minChars:2,
                        matchSubset:1,
                        matchContains:1,
                        cacheLength:10,
                        onItemSelect:selectItem,
                        onFindValue:findValue,
                        formatItem:formatItem,
                        autoFill:true
                    }
                );

                </script>
                <div id="nav-below" class="navigation">
                    <div class="nav-previous"><a href="AlbumServlet?action=view&IdAlbum=${requestScope['id']}"><span class="meta-nav">&laquo;</span> Retour à l'album - ${requestScope['nomAlbum']}</a></div>
                    <div class="nav-next"></div>
                </div>
            </div>
        </div><!-- #content -->
    </div><!-- #container -->
</div><!-- #main -->

<%@ include file="../include/footer.jsp" %>
